package com.zd.springcloud.consumer.mapper;

import com.zd.springcloud.base.BaseMapper;
import com.zd.springcloud.domain.Account;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface AccountMapper extends BaseMapper {

    @Select("select * from t_account where id = #{accountId}")
    Account findAccoutById(Long accountId);

    /**
     * try 阶段 扣钱和预留资源，预留资源字段 + 钱
     * @param money
     * @param accountId
     */

    @Update("update t_account set account_money = account_money - #{money},reduce_money = reduce_money + #{money}  where id = #{accountId}")
    void reduceMoney(@Param("money") double money, @Param("accountId") long accountId);


    /**
     * commit 阶段预留资源字段 - 钱
     * @param money
     * @param accountId
     */

    @Update("update t_account set reduce_money = reduce_money - #{money}  where id = #{accountId}")
    void reduceCommit(@Param("money") double money, @Param("accountId") long accountId);


    /**
     * rollback 阶段 加钱和预留资源，预留资源字段 - 钱，账户加钱
     * @param money
     * @param accountId
     */

    @Update("update t_account set account_money = account_money + #{money},reduce_money = reduce_money - #{money}  where id = #{accountId}")
    void reduceRollback(@Param("money") double money, @Param("accountId") long accountId);



}
